package com.ruoyi.xiaoshou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xiaoshou.domain.SaleBackRequestDetail;
import com.ruoyi.xiaoshou.service.ISaleBackRequestDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 销售退货申请详情Controller
 *
 * @author lmj
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/saleBackRequestDetail")
@Slf4j
public class SaleBackRequestDetailController extends BaseController {
    @Autowired
    private ISaleBackRequestDetailService saleBackRequestDetailService;

    /**
     * 查询销售退货申请详情列表
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:list")
    @GetMapping("/list")
    public TableDataInfo list(SaleBackRequestDetail saleBackRequestDetail) {
        startPage();
        List<SaleBackRequestDetail> list = saleBackRequestDetailService.selectSaleBackRequestDetailList(saleBackRequestDetail);
        return getDataTable(list);
    }

    @RequiresPermissions("xiaoshou:saleBackRequestDetail:list")
    @GetMapping("/useList")
    public TableDataInfo useList(SaleBackRequestDetail saleBackRequestDetail) {
        startPage();
        List<SaleBackRequestDetail> list = saleBackRequestDetailService.useSaleBackRequestDetailList(saleBackRequestDetail);
        return getDataTable(list);
    }

    @PostMapping("getSaleBackRequestDetailByCodes")
    public R<List<SaleBackRequestDetail>> getSaleBackRequestDetailByCodes(@RequestBody String[] codeArray) {
        log.info("SaleBackRequestDetailController getSaleBackDetailByCodes params:{}", (Object) codeArray);
        List<SaleBackRequestDetail> saleBackRequestDetails = saleBackRequestDetailService.getSaleBackRequestDetailByCodes(codeArray);
        return R.ok(saleBackRequestDetails);
    }


    /**
     * 导出销售退货申请详情列表
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:export")
    @Log(title = "销售退货申请详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleBackRequestDetail saleBackRequestDetail) {
        List<SaleBackRequestDetail> list = saleBackRequestDetailService.selectSaleBackRequestDetailList(saleBackRequestDetail);
        ExcelUtil<SaleBackRequestDetail> util = new ExcelUtil<SaleBackRequestDetail>(SaleBackRequestDetail.class);
        util.exportExcel(response, list, "销售退货申请详情数据");
    }

    /**
     * 获取销售退货申请详情详细信息
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(saleBackRequestDetailService.selectSaleBackRequestDetailById(id));
    }

    /**
     * 新增销售退货申请详情
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:add")
    @Log(title = "销售退货申请详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleBackRequestDetail saleBackRequestDetail) {
        return toAjax(saleBackRequestDetailService.insertSaleBackRequestDetail(saleBackRequestDetail));
    }

    @RequiresPermissions("xiaoshou:saleBackRequestDetail:add")
    @Log(title = "销售退货申请详情", businessType = BusinessType.INSERT)
    @PostMapping("addSaleBackRequestDetail")
    public AjaxResult add(@RequestBody List<SaleBackRequestDetail> saleBackRequestDetails) {
        return saleBackRequestDetailService.insertSaleBackRequestDetails(saleBackRequestDetails);
    }

    /**
     * 修改销售退货申请详情
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:edit")
    @Log(title = "销售退货申请详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleBackRequestDetail saleBackRequestDetail) {
        return toAjax(saleBackRequestDetailService.updateSaleBackRequestDetail(saleBackRequestDetail));
    }

    @RequiresPermissions("xiaoshou:saleBackRequestDetail:edit")
    @Log(title = "销售退货申请详情", businessType = BusinessType.UPDATE)
    @RequestMapping("updSaleBackRequestDetail")
    public AjaxResult edit(@RequestBody List<SaleBackRequestDetail> saleBackRequestDetails) {
        return saleBackRequestDetailService.updateSaleBackRequestDetails(saleBackRequestDetails);
    }

    /**
     * 删除销售退货申请详情
     */
    @RequiresPermissions("xiaoshou:saleBackRequestDetail:remove")
    @Log(title = "销售退货申请详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(saleBackRequestDetailService.deleteSaleBackRequestDetailByIds(ids));
    }
}
